package com.kwok.rbac.application.service.impl;

import com.kwok.rbac.application.entity.Privilege;
import com.kwok.rbac.application.mapper.PrivilegeMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kwok.rbac.application.service.PrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 权限表 服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2024-05-25
 */
@Service
public class PrivilegeServiceImpl extends ServiceImpl<PrivilegeMapper, Privilege> implements PrivilegeService {

    @Autowired
    private PrivilegeMapper privilegeMapper;

    //根据角色ID给角色赋予权限(权限的批量添加)
    @Override
    public Boolean privilegeToRole(Integer roleId, List<Integer> privilegeIdList) {
        Integer integer = privilegeMapper.privilegeToRole(roleId, privilegeIdList);
        return integer >= 1;
    }

    //根据角色ID获取角色所拥有的权限(权限的查询)
    @Override
    public List<Privilege> getPrivilegeByRoleId(Integer roleId) {
        return privilegeMapper.getPrivilegeByRoleId(roleId);
    }

    //根据用户ID获取用户所拥有的权限
    @Override
    public List<Privilege> getPrivilegeByUserId(Integer userId) {
        return privilegeMapper.getPrivilegeByUserId(userId);
    }

}
